﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace ExaminationTT.View
{
    public partial class SplashScreen : Form
    {
        private static Thread _thread;
        private delegate void CloseDelegate();
        public SplashScreen()
        {
            InitializeComponent();
            FormBorderStyle = FormBorderStyle.None;
            StartPosition = FormStartPosition.CenterScreen;
            ClientSize = BackgroundImage.Size;
            loader_progressBar.Style = ProgressBarStyle.Marquee;
        }
        private static SplashScreen _splash = null;
        // A static entry point to launch SplashScreen.

        static private void ShowForm()
        {
            _splash = new SplashScreen();
            Application.Run(_splash);
        }
        // A static method to close the SplashScreen

        static public void CloseForm()
        {
            if(_splash == null) return;
            _splash.Invoke(new CloseDelegate(_splash.Close));
        }
        static public void ShowSplashScreen()
        {
            // Make sure it is only launched once.
            if (_splash != null)
                return;
            _thread = new Thread(new ThreadStart(SplashScreen.ShowForm)) {IsBackground = true};
            _thread.SetApartmentState(ApartmentState.STA);
            _thread.Start();
        }
    }
}
